﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>登录</title>
		<link rel="stylesheet" type="text/css" href="/static/css/global.css">
		<link rel="stylesheet" href="/static/css/login1.css" />
	</head>
	<body>
		
		<div class="center">
			<h3 id = "title">登录</h3>
			<div class="cen-left" style="display:block;">
					<iframe id = "iframId" src="http://passport2.chaoxing.com/cloudscanlogin?mobiletip=排课系统登陆确认&pcrefer=http://pk.chaoxing.com/loginByDomianUser"  style="width: 400px;height: 500px;}" frameborder="no"></iframe>
			</div>
			<div class="cen-right">
				<h4>超星号登录</h4>
				<div class="login-block">
					<div class="tab-con">	
						<div class="id-login" id="id-login">
							<div class="inp-box user-inp">
								<input id="userNum" type="text" placeholder="请输入超星号/手机号"/>
								<span class="error" id="userNumMsg"></span>
							</div>
							<div class="inp-box pass-inp">
								<input id="pwd" type="password"  placeholder="请输入密码"/>
								<span class="icon-eye"></span>
								<span class="error" id="pwdMsg"></span>
							</div>
							<div class="error-tip">
								<span><!-- 撑样式用 --></span>
							</div>
							<div class="login-btn" onclick="submit();">登录</div>
						</div>

					</div>
				</div>
			</div>
		</div>
		<div class="message" id="message" style="display: none;">
			网站提示
		</div>
		<script type="text/javascript" src="/static/js/jquery-3.3.1.min.js"></script>
		<script>
		var locationUrl = window.location.href;
		
		$(function(){
			if(locationUrl.indexOf("backIndex") != -1){
				$("#iframId").attr("src","http://passport2.chaoxing.com/cloudscanlogin?pcrefer=http://pk.chaoxing.com/backSchool/loginByDomianUser?loginType=morning");
				$("#title").html("日检后台管理系统");
			}
			var windowhh=$(window).height()*0.15;
			   $(".center h3").css("top",-windowhh);
		});
		
            //密码框眼睛图标点击
            $(".icon-eye").on("click",function(){
                if($(this).hasClass("icon-eye-active")){
                    $(this).removeClass("icon-eye-active");
                    $(this).siblings("input").attr("type","password");
                }else{
                    $(this).addClass("icon-eye-active");
                    $(this).siblings("input").attr("type","text");
                }
            })
            
             $("#id-login input").bind("focus",function(){
	             $(this).addClass("clfocus");
			})
	
			$("#id-login input").bind("blur",function(){
				$(this).removeClass("clfocus");
				
				if($(this).val()!=""){
				    $(this).addClass("borders");
				}
				else{
					$(this).removeClass("borders");	
				}
			})
			
			
			$("#id-login .pass-inp").on('input propertychange', function() {
				$(this).find(".icon-eye").hide();
				if($(this).find("input").val().trim()!=""){
					$(this).find(".icon-eye").show();
				}
				verfoVlue();
			})
			
			$("#id-login .user-inp").on('input propertychange', function() {
				verfoVlue();
			})
			
			
			$(".error-tip span").click(function(){
				$(this).toggleClass("hov");
			})
			
			
			window.alert =  function (msg){
				$("#message").html(msg);
				 $("#message").fadeIn();
				 bootHide();
			}
			function bootHide(){
				 setTimeout(function(){
					 $("#message").fadeOut();
				 }, 1500);
			 }
			function verfoVlue(){
				if(checkValue()){
					
					$(".login-btn").addClass("ensure");
				}
				else{
					$(".error").show();
					$(".login-btn").removeClass("ensure");
				}
			}
            //校验参数
			function checkValue(){
            	var flag = true;
				var userNum=$("#userNum").val();
                var pwd=$("#pwd").val();
                var reg = new RegExp("[0-9]+");
        		if (!reg.test(userNum)) {
        			$("#userNumMsg").html('请使用超星号/手机号登陆');
        			flag = false;
        		}else{
        			$("#userNumMsg").html('');
        		}
        		if(pwd==null||pwd==''){
        			$("#pwdMsg").html('密码不可为空');
        			flag = false;
        		}else{
        			$("#pwdMsg").html('');
        		}
				return flag;
			}
            //提交
			function submit(){
				$(".login-btn").attr("onclick","");  
            	var type = "";
				var successUrl = "/tologin";
				if(!checkValue()){
					return ;
				}
				//tologin
				var userNum=$("#userNum").val();
                var pwd=$("#pwd").val();
				$.ajax({
					type : "POST",
					data : {
						userNumber : userNum,
	                	passWord:pwd
					},
					dataType:"JSON",
					url : "/login",// 从后台获取数据
					success : function(data) {
						if(data.status){
							window.location = successUrl;
						}else{
							$("#pwdMsg").html(data.msg);
							$(".login-btn").attr("onclick","submit();");  
						}
					}
				});
			}

		</script>
	</body>
</html>
